/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	///  宠物--可能获得多个
	/// module : structs
	/// </summary>
	public class PetPOD : IPOD 
    {
        public readonly static Func<PetPOD> FACTORY = () => new PetPOD();
		public static Func<PetPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        ///  唯一id
        /// </summary>
		public long id;
		/// <summary>
        /// 配置id
        /// </summary>
		public int cid;
		/// <summary>
        /// 创建时间(毫秒时间戳)
        /// </summary>
		public long createTime;
		/// <summary>
        /// 自定义名字，为空则显式默认名
        /// </summary>
		public string name;
		/// <summary>
        /// 等级
        /// </summary>
		public int level;
		/// <summary>
        /// 当前等级经验
        /// </summary>
		public int exp;
		/// <summary>
        /// 是否锁定状态
        /// </summary>
		public bool isLock;
		/// <summary>
        /// 道具解锁的技能槽数量
        /// </summary>
		public int unlockSlot;
		/// <summary>
        /// 随机属性组1 -- 由于每组长度不一定相同，分开存放
        /// </summary>
        private List<int> m_randAttrGroup1;
		/// <summary>
        /// 随机属性组2
        /// </summary>
        private List<int> m_randAttrGroup2;
		/// <summary>
        /// 随机属性组3
        /// </summary>
        private List<int> m_randAttrGroup3;
		/// <summary>
        /// 装备的随机属性
        /// </summary>
        private List<int> m_usingRandAttrs;
		/// <summary>
        /// 最终属性 -- 全发	
        /// </summary>
		public int[] attrs;
		
		
        public List<int> randAttrGroup1
        {
            get
            {
                if(m_randAttrGroup1 == null)
                {
                    m_randAttrGroup1 = new();
                }
                return m_randAttrGroup1;
            }
            private set => m_randAttrGroup1 = value;
        }
        public List<int> unsafe_randAttrGroup1
        {
        	get => m_randAttrGroup1;
        	set => m_randAttrGroup1 = value;
        }
        public List<int> randAttrGroup2
        {
            get
            {
                if(m_randAttrGroup2 == null)
                {
                    m_randAttrGroup2 = new();
                }
                return m_randAttrGroup2;
            }
            private set => m_randAttrGroup2 = value;
        }
        public List<int> unsafe_randAttrGroup2
        {
        	get => m_randAttrGroup2;
        	set => m_randAttrGroup2 = value;
        }
        public List<int> randAttrGroup3
        {
            get
            {
                if(m_randAttrGroup3 == null)
                {
                    m_randAttrGroup3 = new();
                }
                return m_randAttrGroup3;
            }
            private set => m_randAttrGroup3 = value;
        }
        public List<int> unsafe_randAttrGroup3
        {
        	get => m_randAttrGroup3;
        	set => m_randAttrGroup3 = value;
        }
        public List<int> usingRandAttrs
        {
            get
            {
                if(m_usingRandAttrs == null)
                {
                    m_usingRandAttrs = new();
                }
                return m_usingRandAttrs;
            }
            private set => m_usingRandAttrs = value;
        }
        public List<int> unsafe_usingRandAttrs
        {
        	get => m_usingRandAttrs;
        	set => m_usingRandAttrs = value;
        }
		
		/*-- constructors --*/
		public PetPOD() {}
		public PetPOD(long id, int cid, long createTime, string name, int level, int exp, bool isLock, int unlockSlot, List<int> randAttrGroup1, List<int> randAttrGroup2, List<int> randAttrGroup3, List<int> usingRandAttrs, int[] attrs) {
			this.id = id;
			this.cid = cid;
			this.createTime = createTime;
			this.name = name;
			this.level = level;
			this.exp = exp;
			this.isLock = isLock;
			this.unlockSlot = unlockSlot;
			this.m_randAttrGroup1 = randAttrGroup1;
			this.m_randAttrGroup2 = randAttrGroup2;
			this.m_randAttrGroup3 = randAttrGroup3;
			this.m_usingRandAttrs = usingRandAttrs;
			this.attrs = attrs;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_long(id);
            _out.Write_int(cid);
            _out.Write_long(createTime);
            _out.Write_string(name);
            _out.Write_int(level);
            _out.Write_int(exp);
            _out.Write_boolean(isLock);
            _out.Write_int(unlockSlot);
            _out.Write_list_int(m_randAttrGroup1); 
            _out.Write_list_int(m_randAttrGroup2); 
            _out.Write_list_int(m_randAttrGroup3); 
            _out.Write_list_int(m_usingRandAttrs); 
            _out.Write_intArr(attrs);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            id = _in.Read_long();
            if(!_in.HasRemaining()) return;
            cid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            createTime = _in.Read_long();
            if(!_in.HasRemaining()) return;
            name = _in.Read_string();
            if(!_in.HasRemaining()) return;
            level = _in.Read_int();
            if(!_in.HasRemaining()) return;
            exp = _in.Read_int();
            if(!_in.HasRemaining()) return;
            isLock = _in.Read_boolean();
            if(!_in.HasRemaining()) return;
            unlockSlot = _in.Read_int();
            if(!_in.HasRemaining()) return;
            m_randAttrGroup1 = _in.Read_list_int();
            if(!_in.HasRemaining()) return;
            m_randAttrGroup2 = _in.Read_list_int();
            if(!_in.HasRemaining()) return;
            m_randAttrGroup3 = _in.Read_list_int();
            if(!_in.HasRemaining()) return;
            m_usingRandAttrs = _in.Read_list_int();
            if(!_in.HasRemaining()) return;
            attrs = _in.Read_intArr();
        }
		
		public PetPOD Clone() {
            PetPOD o = DynamicFactory();
            o.id = id;
            o.cid = cid;
            o.createTime = createTime;
            o.name = name;
            o.level = level;
            o.exp = exp;
            o.isLock = isLock;
            o.unlockSlot = unlockSlot;
            if (m_randAttrGroup1 != null) {
                o.m_randAttrGroup1 = new (m_randAttrGroup1);
            }
            if (m_randAttrGroup2 != null) {
                o.m_randAttrGroup2 = new (m_randAttrGroup2);
            }
            if (m_randAttrGroup3 != null) {
                o.m_randAttrGroup3 = new (m_randAttrGroup3);
            }
            if (m_usingRandAttrs != null) {
                o.m_usingRandAttrs = new (m_usingRandAttrs);
            }
            if (attrs != null) {
                o.attrs = (int[])attrs.Clone();
            }
            return o;
        }
        
        public void Clear() {
            id = default;
            cid = default;
            createTime = default;
            name = default;
            level = default;
            exp = default;
            isLock = default;
            unlockSlot = default;
            m_randAttrGroup1 = default;
            m_randAttrGroup2 = default;
            m_randAttrGroup3 = default;
            m_usingRandAttrs = default;
            attrs = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "PetPOD [";
			str += "id=";
			str += id;
			str += ", cid=";
			str += cid;
			str += ", createTime=";
			str += createTime;
			str += ", name=";
			str += name;
			str += ", level=";
			str += level;
			str += ", exp=";
			str += exp;
			str += ", isLock=";
			str += isLock;
			str += ", unlockSlot=";
			str += unlockSlot;
			str += ", randAttrGroup1=";
			str += m_randAttrGroup1.ToString<int>();
			str += ", randAttrGroup2=";
			str += m_randAttrGroup2.ToString<int>();
			str += ", randAttrGroup3=";
			str += m_randAttrGroup3.ToString<int>();
			str += ", usingRandAttrs=";
			str += m_usingRandAttrs.ToString<int>();
			str += ", attrs=";
			str += attrs;
			str += "]";
			return str;
		}
		
	}
}